import HTTP from '@/libs/http'

class LoginApi extends HTTP {
  /**
   * @description: 登录
   * @author lsr
   * @date 2021.03.01
   * @param {String} loginName 用户名
   * @param {String} passWord 密码
   * @param {String} regionCode 行政区划
   */
  login({ loginName, passWord, regionCode }) {
    return this.request({
      method: 'POST',
      url: '/smart/smart-app/user/login',
      data: {
        loginName,
        passWord,
        regionCode
      }
    })
  }

  /**
   * @description: 登出
   * @author lsr
   * @date 2021.03.01
   */
  logout() {
    return this.request({
      method: 'POST',
      url: '/smart/smart-app/user/logout'
    })
  }

  /**
   * @description: 企业微信授权登录
   * @author lsr
   * @date 2021.09.14
   * @param {String} code 企业微信回调接口返回的code
   */
  authLogin({ code }) {
    return this.request({
      method: 'GET',
      url: '/smart/smart-app/user/weixinbinding',
      params: {
        code
      }
    })
  }

  /**
   * @description: 获取菜单树
   */
  getMenuTree() {
    return this.request({
      method: 'GET',
      url: '/smart/smart-app/user/function'
    })
  }
}
class ApplyApi extends HTTP {
  /**
   * @description: 申请
   * @author llx
   * @date 2021.03.03
   * @param {String} loginName 用户名
   * @param {String} userName 姓名
   * @param {String} type 人员类别
   * @param {String} regionCode 行政区划
   * @param {String} validateCode 验证码
   */
  apply({ loginName, userName, type, regionCode, validateCode }) {
    return this.request({
      method: 'POST',
      url: '/smart/smart-app/user/register',
      data: {
        loginName,
        userName,
        type,
        regionCode,
        validateCode
      }
    })
  }
}
class PasswordApi extends HTTP {
  /**
   * @description: 修改密码
   * @author lsr
   * @date 2021.03.04
   * @param {String} loginName 用户名
   * @param {String} newPassWord 新密码
   * @param {String} validateCode 验证码
   */
  updatePassword({ loginName, newPassWord, validateCode }) {
    return this.request({
      method: 'POST',
      url: '/smart/smart-app/user/password_before',
      data: {
        loginName,
        newPassWord,
        validateCode
      }
    })
  }
}

class LoginClass {
  constructor() {
    this.Login = new LoginApi()
    this.Apply = new ApplyApi()
    this.Password = new PasswordApi()
  }
}

const Login = new LoginClass()

export default Login
